﻿/*
 * Created by SharpDevelop.
 * User: developer
 * Date: 10/27/2010
 * Time: 9:53 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Xml;

namespace xmldict
{
	/// <summary>
	/// Description of test.
	/// </summary>
	public class test
	{
		private static IMinimalDict createViaDict(int range){
			IMinimalDict dict = new DictAdapter();
			dict["Hello"] = 1;
			if (range <2){
				return dict;
			}
			Dictionary<string, object> at = new Dictionary<string, object>();
			dict["@"] = at;
			at["MyAttr"]="MyValue";
			at["@"] = "InternalText";
			Dictionary<string, object> world = new Dictionary<string, object>();
			dict["World"] = world;
			world["My"] =2;
			if (range <3){
				return dict;
			}
			IMinimalList list = new ListAdapter();
			dict["list"]= list;
			for (int i =16 ;i< 20; i++){
				list.Add(i*i);
			}
			return dict;
		}
		private static XmlDocument PrintXML(IMinimalDict dict){
			XmlDocument document = new XmlDocument();
			document.AppendChild(document.CreateElement("root"));		
			XMLUtils.WriteDict(document, document.DocumentElement, dict);
			XmlTextWriter writer = new XmlTextWriter(Console.OpenStandardOutput(), Console.OutputEncoding);
			writer.Formatting = Formatting.Indented;
			document.Save(writer);
			Console.WriteLine();
			return document;
		}

		public static void Main(string [] args)
		{			
			IMinimalDict source = createViaDict(3);
			XmlDocument document = PrintXML(source);
			Console.WriteLine("-----------");
			IMinimalDict dest = new DictAdapter();
			XMLUtils.ReadDict(document.DocumentElement, dest);
			PrintXML(dest);
		}
	}
}
